<?php

class alumnikantor_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = "alumni_has_kantor";
    }

    function insert($alumniid, $kantorid, $bagian, $jabatan, $daritahun, $sampaitahun) {
        $dt = array("alumniid" => $alumniid,
            "kantorid" => $kantorid,
            "bagian" => $bagian,
            "jabatan" => $jabatan,
            "daritahun" => $daritahun,
            "sampaitahun" => $sampaitahun);
        $this->db->insert($this->tableName, $dt);
        return $this->db->insert_id();
    }

    function update($alumnikantorid, $dt, $where = "") {
        $this->db->where("alumnikantorid", $alumnikantorid);
        if ($where != "")
            $this->db->where($where);
        $this->db->update($this->tableName, $dt);
    }

    function delete($alumnikantorid, $where = "") {
        $this->db->where("alumnikantorid", $alumnikantorid);
        if ($where != "")
            $this->db->where($where);
        $this->db->delete($this->tableName);
    }

    function getById($alumnikantorid, $where = "") {
        $this->db->select($this->tableName.".*, kantor.kantornama");
        $this->db->from($this->tableName);
        $this->db->join("kantor", $this->tableName.".kantorid = kantor.kantorid");
        $this->db->where("alumnikantorid", $alumnikantorid);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row();
    }

    function getAll($startpage = "0", $perpage = "10", $where = "", $orderby = "") {
        if ($where != "")
            $this->db->where($where);
        $this->db->limit($perpage, $startpage);
        if ($orderby != "")
            $this->db->order_by($orderby);
        return $this->db->get($this->tableName)->result();
    }

    function getKantor($alumniid) {
        $this->db->select("alumni_has_kantor.*, kantor.kantornama");
        $this->db->from($this->tableName);
        $this->db->join("kantor", $this->tableName . ".kantorid = kantor.kantorid");
        $this->db->where("alumniid", $alumniid);
        $this->db->order_by("daritahun");
        return $this->db->get()->result();
    }

    function getAllCount($where = "") {
        $this->db->select("COUNT(*) JUMLAH");
        $this->db->from($this->tableName);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row()->JUMLAH;
    }

}

?>